package main

import (
	"fmt"
	"os"
	"time"
)

func main() {
	ch := make(chan int)
	quit := make(chan bool)

	go func() {
		for true {
			select {
			case num := <-ch:
				fmt.Println("接收： ", num)
			case <-time.After(10 * time.Second):
				fmt.Println("超时")
				quit <- true
			}
		}
	}()

	go func() {
		timer := time.NewTimer(0 * time.Second)
		for i := 1; i < 10; i++ {
			<-timer.C
			ch <- i
			fmt.Println("写入", i, " time: ", time.Now())
			timer.Reset(time.Duration(i) * time.Second)
		}
	}()

	<-quit
	fmt.Println("程序结束")
	os.Exit(1)
}
